<?php
/*
 * @Author: 莫极通
 * @Phone: 13450159681
 * @Description: 
 * @Date: 2025-02-11 14:46:03
 * @LastEditTime: 2025-02-19 17:09:59
 */

namespace app\index\controller;

use think\exception\ValidateException;
use app\model\Article;
use app\model\ArticleCategory;

class ArticleController extends Base
{

    public function list()
    {

        $query = Article::where(['weid' => weid(), 'status' => 1]);
        $cid = input('post.cid');
        if (!empty($cid)) {
            $query->where('cid', $cid);
        }
        $keyword = input('post.keyword', '', 'serach_in');
        if (!empty($keyword)) {
            $query->where('title', 'like', '%' . $keyword . '%');
        }

        $data = $query->order('id desc')
            ->select()
            ->toArray();

        return $this->json(['data' => $data]);
    }

    public function detail()
    {
        $id = input('get.id');
        if (!empty($id)) {
            $where['weid'] = weid();
            $where['id'] = $id;
            $data = Article::where($where)->find();
            if (!empty($data)) {
                $data = $data->toArray();
                $data['create_time'] =  time_ymd($data['create_time']);
                $data['cate'] =  ArticleCategory::getTitle($data['cid']);
            }
        }
        return $this->json(['data' => $data]);
    }
}
